<?php
class model_technician extends Model
{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function newTechnician($data)
	{
		$this->db->insert("technician", $data);
	}
	
	function updateTechnician($data, $id)
	{
		$this->db->where("id", $id);
		$this->db->upate("technician", $data);
	}
	
	function updatePhone($newData, $id)
	{
		$data = array(	"contact1" => $newData);
		$this->db->where("id", $id);
		$this->db->update("technician",  $data);
	}

	function updateMobile($newData, $id)
	{
		$data = array(	"contact2" => $newData);
		$this->db->where("id", $id);
		$this->db->update("technician",  $data);
	}

	function updateEmail($newData, $id)
	{
		$data = array(	"contact3" => $newData);
		$this->db->where("id", $id);
		$this->db->update("technician",  $data);
	}
	
	function getJobsForTech($techId)
	{
		$this->db	->select("*")
					->from("worklog")
					->join("job", "worklog.job_id=job.id")
					->where(array("worklog.tech_id" => $techId));
		$r = $this->db->get();
		return $r->result_query();
	}

	function activate($id)
	{
		$data = array("active" =>1);
		$this->db->where("id", $id);
		$this->db->update("technician", $data);
	}

	function deactivate($id)
	{
		$data = array("active" =>0);
		$this->db->where("id", $id);
		$this->db->update("technician", $data);
	}
}